import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 				= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		// 搜索表单列表
		forms : [
			{ label: '操作人',		name: 'operator_name' },
			{ label: '操作时间',		names: ['created_time_start_date','created_time_end_date'],	type: 'date-range' },
			{ label: '类型',			name: 'dtype',	type: 'select', loading:true },
			{ label: '描述',			name: 'title' },
		]
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		this.fetch()
	}
	
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 设备状态
			$fn.setRow( forms, 'dtype', await f.getCache( { api:'slogSelect' } ))
			
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'slog/sysLogs')
	
	// 表单
	cols = [
		{ title: 'Id', 			dataIndex: 'id', 				...$fn.table.num },
		{ title: '模块', 		dataIndex: 'dtype_str', 		width:200 },
		{ title: '操作人', 		dataIndex: 'operator_name', 	...$fn.table.name },
		{ title: '操作时间', 	dataIndex: 'created_time', 		...$fn.table.time },
		{ title: '描述', 		dataIndex: 'title', 			width:900 },
	]
	
	render(){
		const { details, beforeDetails } = this.state
		return (
			<>
				<Page title='系统日志'>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this,{type:1, onSelectOk: ( keys,rows )=>{
					const row = rows[rows.length-1]
					if(row){
						const details = row.details
						const beforeDetails = row.before_details
						this.setState({ details, beforeDetails })
					}
				}}) }
					<div class='bor1 mt5'>
						{/* 详细信息 */}
						<div>
							<div className='ptb5 tc b bbor1' style={{backgroundColor:'#f0fffc'}} >详细信息</div>
							<div className='mtb10 plr10 oys scrollbar' style={{minHeight:20}} >{ details }</div>
						</div>
						{/* 修改前信息 */}
						<div>
							<div className='ptb5 tc b bbor1 tbor1' style={{backgroundColor:'#f0fffc'}} >修改前信息</div>
							<div className='mtb10 plr10 oys scrollbar' style={{minHeight:20}} >{ beforeDetails }</div>
						</div>
					</div>
				</Page>
			</>
		)
	}
}

export default Index